<?php

namespace App\Entity\Wuliu;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use App\Repository\Wuliu\WuliuUserLevelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass=WuliuUserLevelRepository::class)
 */
class WuliuUserLevel
{
    /**
     * @Common(cnName="#",editType="text",listType="text")
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"level"})
     */
    private $id;

    /**
     * @Common(cnName="名称",editType="text",listType="text",width="")
     * @ORM\Column(type="string", length=255)
     * @Groups({"level"})
     */
    private $name;

    /**
     * @Common(cnName="等级",editType="text",listType="text")
     * @ORM\Column(type="integer")
     * @Groups({"level"})
     */
    private $level;

    /**
     * @Common(cnName="充值费用",editType="text",listType="text")
     * @ORM\Column(type="float", nullable=true)
     * @Groups({"level"})
     */
    private $price;

    /**
     * @Common(cnName="会员期限（天）",editType="text",listType="text")
     * @ORM\Column(type="integer", nullable=true)
     * @Groups({"level"})
     */
    private $days;

    /**
     * @Common(cnName="别名",editType="text",listType="text")
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"level"})
     */
    private $alias;

    /**
     * @Common(cnName="返佣金额",editType="text",listType="text")
     * @ORM\Column(type="float", nullable=true)
     * @Groups({"level"})
     */
    private $repay;

    /**
     * @ORM\OneToMany(targetEntity=WuliuUser::class, mappedBy="level", orphanRemoval=true)
     */
    private $wuliuUsers;

    public function __construct()
    {
        $this->wuliuUsers = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getLevel(): ?int
    {
        return $this->level;
    }

    public function setLevel(int $level): self
    {
        $this->level = $level;

        return $this;
    }

    public function getPrice(): ?float
    {
        return $this->price;
    }

    public function setPrice(?float $price): self
    {
        $this->price = $price;

        return $this;
    }

    public function getDays(): ?int
    {
        return $this->days;
    }

    public function setDays(?int $days): self
    {
        $this->days = $days;

        return $this;
    }

    public function getAlias(): ?string
    {
        return $this->alias;
    }

    public function setAlias(?string $alias): self
    {
        $this->alias = $alias;

        return $this;
    }

    public function getRepay(): ?float
    {
        return $this->repay;
    }

    public function setRepay(?float $repay): self
    {
        $this->repay = $repay;

        return $this;
    }

    /**
     * @return Collection|WuliuUser[]
     */
    public function getWuliuUsers(): Collection
    {
        return $this->wuliuUsers;
    }

    public function addWuliuUser(WuliuUser $wuliuUser): self
    {
        if (!$this->wuliuUsers->contains($wuliuUser)) {
            $this->wuliuUsers[] = $wuliuUser;
            $wuliuUser->setLevel($this);
        }

        return $this;
    }

    public function removeWuliuUser(WuliuUser $wuliuUser): self
    {
        if ($this->wuliuUsers->contains($wuliuUser)) {
            $this->wuliuUsers->removeElement($wuliuUser);
            // set the owning side to null (unless already changed)
            if ($wuliuUser->getLevel() === $this) {
                $wuliuUser->setLevel(null);
            }
        }

        return $this;
    }
}
